﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using T.FAS.Runtime.DataAccess.SPI;
using T.FAS.Runtime.DataAccess.ShardingRule;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.FAS.Runtime.DataAccess.SQLDom;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.DataAccess.SPI
{
    /// <summary>
    /// 数据访问服务接口
    /// </summary>
    public interface IUnifiedDataAccessService
    {
        IDataAccessEngine DataAccessEngine { get; set; }
        #region Save

        /// <summary>
        /// 保存CDO数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="commonResultObject">通用结果对象</param>
        TResult SaveDataForCDO(CompositeDataObject compositeDataObject, TRecord data, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 保存指定对象的数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="compositeNodeObjectID">组合数据对象节点ID</param>
        /// <param name="commonResultObject">通用结果对象</param>
        TResult SaveDataForCDO(CompositeDataObject compositeDataObject, string compositeNodeObjectID, TRecord data, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 保存数据对象数据
        /// </summary>
        /// <param name="dataObject">数据对象</param>
        /// <param name="commonResultObject">通用结果对象</param>
        TResult SaveDataForDataObject(DataObject dataObject, TRecord data, Dictionary<string, object> exrParams = null);

        #endregion

        #region Update

        /// <summary>
        /// 更新CDO数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="commonResultObject">通用结果对象</param>
        TResult UpdateDataForCDO(CompositeDataObject compositeDataObject, TRecord data, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 更新CDO数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="compositeNodeObjectID">组合数据对象节点ID</param>
        /// <param name="commonResultObject">通用结果对象</param>
        TResult UpdateDataForCDO(CompositeDataObject compositeDataObject, string compositeNodeObjectID, TRecord data, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 更新数据对象数据
        /// </summary>
        /// <param name="dataObject">数据对象</param>
        /// <param name="commonResultObject">通用结果对象</param>
        TResult UpdateDataForDataObject(DataObject dataObject, TRecord data, Dictionary<string, object> exrParams = null);

        BatchUpdateResult BatchUpdateDataForCDO(CompositeDataObject compositeDataObject, List<TRecord> datas, Dictionary<string, object> exrParams = null);
        #endregion

        #region Delete

        /// <summary>
        ///  删除CDO数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="dataId">数据唯一标识</param>        
        void DeleteDataForCDO(CompositeDataObject compositeDataObject, string dataId, Dictionary<string, object> exrParams = null);

        /// <summary>
        ///  批量删除CDO数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="dataIds">数据唯一标识集合</param>        
        void DeleteDataSetForCDO(CompositeDataObject compositeDataObject, IList<string> dataIds, Dictionary<string, object> exrParams = null);

        /// <summary>
        ///  删除CDO节点数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="compositeNodeObjectID">CDO节点ID</param>
        /// <param name="dataId">数据唯一标识</param>        
        void DeleteDataForCDO(CompositeDataObject compositeDataObject, string compositeNodeObjectID, string dataId, Dictionary<string, object> exrParams = null);

        /// <summary>
        ///  删除数据
        /// </summary>
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="compositeNodeObjectID">CDO节点ID</param>
        /// <param name="dataIds">数据唯一标识集合</param>        
        void DeleteDataSetForCDO(CompositeDataObject compositeDataObject, string compositeNodeObjectID, IList<string> dataIds, Dictionary<string, object> exrParams = null);

        /// <summary>
        ///  删除数据对象数据
        /// </summary>
        /// <param name="dataObject">数据对象</param>
        /// <param name="dataId">数据唯一标识</param>        
        void DeleteDataForDataObject(DataObject dataObject, string dataId, Dictionary<string, object> exrParams = null);

        /// <summary>
        ///  批量删除数据对象数据
        /// </summary>
        /// <param name="dataObject">数据对象</param>
        /// <param name="dataIds">数据唯一标识集合</param>        
        void DeleteDataSetForDataObject(DataObject dataObject, IList<string> dataIds, Dictionary<string, object> exrParams = null);

        #endregion

        #region Query

        /// <summary>
        /// 获取指定CDO的数据
        /// </summary>        
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="dataId">数据唯一标识</param>        
        /// <returns>通用结果数据</returns>
        TResult QueryDataForCDO(CompositeDataObject compositeDataObject, string dataId, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 获取指定CDO的数据
        /// </summary>        
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="compositeNodeObjectID">CDO节点ID</param>
        /// <param name="dataId">数据唯一标识</param>        
        /// <returns>通用结果数据</returns>
        TResult QueryDataForCDO(CompositeDataObject compositeDataObject, string compositeNodeObjectID, string dataId, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 获取指定CDO的数据
        /// </summary>        
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="queryFilter">查询过滤器</param>              
        /// <returns>通用结果数据</returns>
        TResult QueryDataForCDO(CompositeDataObject compositeDataObject, QueryFilter queryFilter, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 获取指定CDO的数据
        /// </summary>        
        /// <param name="compositeDataObject">CDO</param>
        /// <param name="compositeNodeObjectID">CDO节点ID</param>
        /// <param name="queryFilter">查询过滤器</param>        
        /// <returns>通用结果数据</returns>
        TResult QueryDataForCDO(CompositeDataObject compositeDataObject, string compositeNodeObjectID, QueryFilter queryFilter, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 获取指定数据对象的数据
        /// </summary>        
        /// <param name="dataObject">数据对象</param>
        /// <param name="dataId">数据唯一标识</param>        
        /// <returns>通用结果数据</returns>
        TResult QueryDataForDataObject(DataObject dataObject, string dataId, Dictionary<string, object> exrParams = null);

        TResult QueryDataForDataObject(DataObject dataObject, Dictionary<string, object> parameters, Dictionary<string, object> exrParams = null);

        /// <summary>
        /// 执行DataQuery数据查询
        /// </summary>
        /// <param name="dataQuery">DataQuery</param>
        /// <param name="parameters">查询实际参数列表</param>
        /// <returns>通用结果数据</returns>
        TResult QueryDataForDataQuery(DataQuery dataQuery, Dictionary<string,object> parameters, Dictionary<string, object> exrParams = null);

        #endregion

        DataSet Query(FasDBCommand fasDBCommand);

        string GetDQActionSQL(DataQuery dataQuery);

        TRecord RefreshTRecord(CompositeDataObject cdo, TRecord record);

        bool IsHaveStateMachine(CompositeDataObject cdo);
    }
}
